package com.wz.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wz.common.utils.text.Convert;
import com.wz.device.entity.BasMaintenanceRecords;
import com.wz.device.mapper.BasMaintenanceRecordsMapper;
import com.wz.device.service.BasMaintenanceRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Service
public class BasMaintenanceRecordsServiceImpl extends ServiceImpl<BasMaintenanceRecordsMapper, BasMaintenanceRecords> implements BasMaintenanceRecordsService {

    @Autowired
    private BasMaintenanceRecordsMapper basMaintenanceRecordsMapper;

    @Override
    public List<BasMaintenanceRecords> selectBasMaintenanceRecordsList(BasMaintenanceRecords basMaintenanceRecords) {
        // 生成数据权限过滤条件
        return basMaintenanceRecordsMapper.selectBasMaintenanceRecordsList(basMaintenanceRecords);
    }

    @Override
    public int insertBasMaintenanceRecords(BasMaintenanceRecords basMaintenanceRecords) {
        try {
            // 新增设备故障记录信息
            String s = String.valueOf(System.currentTimeMillis());
            String substring = s.substring(s.length() - 6);
            basMaintenanceRecords.setId(substring);
            int rows = basMaintenanceRecordsMapper.insertBasMaintenanceRecords(basMaintenanceRecords);
            return rows;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public BasMaintenanceRecords selectBasMaintenanceRecords(String id) {
        return basMaintenanceRecordsMapper.selectBasMaintenanceRecordsById(id);
    }

    @Override
    public int updateBasMaintenanceRecords(BasMaintenanceRecords basMaintenanceRecords) {
        try {
            return basMaintenanceRecordsMapper.updateBasMaintenanceRecords(basMaintenanceRecords);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int deleteBasMaintenanceRecordsByIds(String ids) {
        try {
            String[] maintenanceRecordsIds = Convert.toStrArray(ids);
            return basMaintenanceRecordsMapper.deleteBasMaintenanceRecordsByIds(maintenanceRecordsIds);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
